<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>基于 CSS 的过渡效果</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/3.2.40/vue.global.js"></script>
    <style>
      /* 开始与离开动画都是透明度渐变动画 */
      .fade-enter-active,
      .fade-leave-active {
        transition: opacity 0.5s ease;
      }

      /* 开始初始透明为0，结束最终透明度也为0 */
      .fade-enter-from,
      .fade-leave-to {
        opacity: 0;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <button @click="show = !show">切换动画</button>
      <transition name="fade">
        <div v-if="show">Hello Vue3!</div>
      </transition>
    </div>

    <script>
      const { createApp } = Vue

      createApp({
        data() {
          return {
            show: false,
          }
        },
      }).mount('#app')
    </script>
  </body>
</html>
